USE HW_Rental
go
IF(@@ERROR > 0)
BEGIN 
RAISERROR 15000 'error has been raise, stop excuting sql;'
RETURN
END 
go

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_menu]') AND type in (N'U'))
DROP TABLE [dbo].[sys_menu]
GO
CREATE TABLE [dbo].[sys_menu](
	[menu_code] [nvarchar](30) PRIMARY KEY,
	[menu_name] [nvarchar](250) NULL,
	[menu_parent] [nvarchar](30) NULL,
	[url] [nvarchar](250) NULL,
	[sequence] [int] NULL,
	[state] [nchar](1),
	[img] [nvarchar](250) NULL,
	[icon_cls] [nvarchar](250) NULL,
	[remark] [nvarchar](250) NULL,
)
go

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_user]') AND type in (N'U'))
DROP TABLE [dbo].[sys_user]
GO

CREATE TABLE [dbo].[sys_user](
	[user_id] [int] IDENTITY(1,1)  PRIMARY KEY,
	[user_code] [nvarchar](30) NULL,
	[user_name] [nvarchar](100) NULL,
	[password] [nvarchar](100) NULL,
	[remark] [nvarchar](250) NULL,
	[state] [nchar](1) NULL
	)
	go

-- sys_role
IF  EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.tables A WHERE A.table_name = 'sys_role')
BEGIN
	DROP TABLE sys_role
END
go

	CREATE TABLE sys_role(
	role_code NVARCHAR(30),
	role_name NVARCHAR(30),
	remark	NVARCHAR(250),
	[state] NCHAR(1)
	)  
GO


INSERT INTO sys_user(user_code,user_name,password)
VALUES('admin','Admin','c4ca4238a0b923820dcc509a6f75849b')	
go

-- sys
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('sys','System','','',10,0,'','','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('sys_user','User','sys','/sys/user',10,0,'','icon-user_mgt','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('sys_role','Role','sys','/sys/role',10,0,'','icon-role_mgt','') 
go

-- master
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('master','Master','','',20,0,'','','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('unit_m','Unit','master','/master/unit',10,0,'','icon-unit','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('agent_m','Agent','master','/master/agent',10,0,'','icon-agent','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('features_m','Features','master','/master/features',10,0,'','icon-features','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('busNature_m','Business Nature','master','/master/busNature',10,0,'','icon-busNature','')
INSERT INTO sys_menu(menu_code, menu_name,menu_parent,url,sequence,state,img,icon_cls,remark)
VALUES('handover_con_m','Handover Condition','master','/master/handoverCon',10,0,'','icon-handoverCon','')


